﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using FTchina.Library;
namespace FTchina.OA
{
    /// <summary>
    ///Email 的摘要说明
    /// </summary>
    public class Email
    {
        public Email()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        public static void Send(string strto, string strSubject, string strBody)
        {
            try
            {
                //邮件发送者
                MailAddress from = new MailAddress("sd-lcgly@chinaunicom.cn");
                //邮件接收者

                MailAddress to = new MailAddress(strto);
                MailMessage mailobj = new MailMessage(from, to);
                // 添加发送和抄送
                // mailobj.To.Add("");
                // mailobj.CC.Add("");
                //邮件标题
                mailobj.Subject = strSubject;
                //邮件内容
                mailobj.Body = strBody;

                //邮件不是html格式
                mailobj.IsBodyHtml = true;
                //邮件编码格式
                //  mailobj.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
                mailobj.BodyEncoding = System.Text.Encoding.UTF8;
                //邮件优先级
                mailobj.Priority = MailPriority.High;


                // Attachment atc = new Attachment(Server.MapPath("~/mailattch/shouce.rar"), System.Net.Mime.MediaTypeNames.Application.Octet);
                // mailobj.Attachments.Add(atc);

                //Initializes a new instance of the System.Net.Mail.SmtpClient class
                //that sends e-mail by using the specified SMTP server.
                SmtpClient smtp = new SmtpClient("sd.smtp.chinaunicom.cn");
                //或者用：
                //SmtpClient smtp = new SmtpClient();
                //smtp.Host = mailServer;
                //不使用默认凭据访问服务器
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential("sd-lcgly", "wbh123!!");
                //使用network发送到smtp服务器
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;


                //开始发送邮件
                smtp.Send(mailobj);

                LogHelper.Info(strto + "email send ok");
                
            }
            catch (SystemException er)
            {
                LogHelper.Error(strto + er.Message);
            }
        }


    }
}